package com.park.platform.service.impl;

import com.park.common.constant.IDBConstant;
import com.park.common.poo.OtherResource;
import com.park.common.util.DateUtil;
import com.park.common.util.StrUtil;
import com.park.platform.dao.IBaseDao;
import com.park.platform.service.IResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class ResourceServiceImpl extends BaseService implements IResourceService {

    @Autowired
    private IBaseDao baseDao;

    @Override
    public OtherResource saveRedactorResource(String originalFilename, Integer fileSize, int serviceId, String serviceType, String resourceType){

        String resourceName = "cms_" + StrUtil.getUUID() + originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();

        OtherResource resource = new OtherResource();

        resource.setResourceServiceId(serviceId);
        resource.setResourceServiceType(serviceType);
        resource.setResourceType(resourceType);
        resource.setResourceOriginal(originalFilename);
        resource.setResourceName(resourceName);
        resource.setResourcePath(resourceName);
        resource.setFileSize(fileSize);
        resource.setStatus(IDBConstant.LOGIC_STATUS_YES);
        resource.setCreateTime(DateUtil.getNowDate());

        baseDao.save(resource, resource.getResourceId());
        return resource;
    }

    @Override
    public void save(OtherResource resource) {
        baseDao.save(resource, resource.getResourceId());
    }

}
